/*
 * @Author: bigflower
 * @Date: 2022-04-13 16:20:38
 * @LastEditors: BigFlower
 * @LastEditTime: 2022-08-25 21:46:34
 * @Description: file content
 * @FilePath: \wochat-vue3-ts-pinia\src\store\user.ts
 */

import { defineStore, acceptHMRUpdate } from "pinia";
import { WEBSOCKET_MSG_TYPE } from "@/common/constant";
import websocket from "@/service/wochatWebsocket";
import { guid } from "@/common/random";
import { ref } from "vue";

export const useUserStore = defineStore("userSotre", () => {
  const avatorUrl = ref<string>("avator/avator.jpg");
  const username = ref<string>("");
  const hasLogined = ref<boolean>(false);

  const changeAvator = () => {
    avatorUrl.value = "avator/pkq.jpg";
  };
  const login = (username: string) => {
    websocket.send({
      cmd: WEBSOCKET_MSG_TYPE.LOGIN,
      data: { username },
    });
  };
  const loginSuccess = () => {
    hasLogined.value = true;
  };
  return { avatorUrl, login, loginSuccess };
});

if (import.meta.hot) {
  import.meta.hot.accept(acceptHMRUpdate(useUserStore, import.meta.hot));
}
